package com.schoolCommunity.controller;

import com.schoolCommunity.pojo.ConfessionWall;
import com.schoolCommunity.pojo.ConfessionWallMessage;
import com.schoolCommunity.pojo.Information;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class ConfessionWallController {

    @Autowired
    private RestTemplate restTemplate;

    private static final String REST_URL_PREFIX = "http://SCHOOLCOMMUNITY-CONFESSIONWALL";

    //负载均衡测试用
    @GetMapping("/ConfessionWallHello")
    public String hello() {
        System.out.println("-------------------进入了测试--------------");
        return restTemplate.getForObject(REST_URL_PREFIX + "/hello", String.class);
    }

    //用户添加表白墙

    /**
     * 需要写入的有：
     * 用户ID，主题，内容，时间，昵称，
     */
    @PostMapping("/InsertConfession")
    public Information InsertConfession(@RequestBody ConfessionWall ConfessionWall) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/InsertConfession", ConfessionWall, Information.class);
    }

    //删除表白墙，同时删除该表白墙下面的留言，管理员功能？
    @PostMapping("/DeleteConfessionWall")
    public Information DeleteConfessionWall(@RequestBody int id) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/DeleteConfessionWall", id, Information.class);
    }

    //获取所有表白墙，管理者端
    @PostMapping("/getAllConfessionWallForAdmin")
    public Information getAllConfessionWallForAdmin() {
        return restTemplate.postForObject(REST_URL_PREFIX + "/getAllConfessionWallForAdmin", null, Information.class);
    }

    //获取所有未通过审核的表白墙，管理者端
    @PostMapping("/getNotPassConfessionWall")
    public Information getNotPassConfessionWall() {
        return restTemplate.postForObject(REST_URL_PREFIX + "/getNotPassConfessionWall", null, Information.class);
    }

    //获取所有尚未审核的表白墙
    @PostMapping("/getNotSuggestConfessionWall")
    public Information getNotSuggestConfessionWall() {
        return restTemplate.postForObject(REST_URL_PREFIX + "/getNotSuggestConfessionWall", null, Information.class);
    }

    //管理员审核表白墙
    @GetMapping("/AdminSuggestConfessionWall/{ConfessionWallId}/{suggestResult}")
    public Information AdminSuggestConfessionWall(@PathVariable("ConfessionWallId") long ConfessionWallId, @PathVariable("suggestResult") int suggestResult) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/AdminSuggestConfessionWall/" + ConfessionWallId + "/" + suggestResult, Information.class);
    }

    //管理员审核表白墙后发布通过的表白墙。
    @GetMapping("/AdminPublishConfessionWall/{PublishConfessionWalls}")
    public Information AdminPublishConfessionWall(@PathVariable("PublishConfessionWalls") List<Long> PublishConfessionWalls) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/AdminPublishConfessionWall/" + PublishConfessionWalls, Information.class);
    }

    //获取所有表白墙，普通用户端
    @PostMapping("/getAllConfessionWall")
    public Information getAllConfessionWall() {
        return restTemplate.postForObject(REST_URL_PREFIX + "/getAllConfessionWall", null, Information.class);
    }

    //获取指定期数的表白墙
    @GetMapping("/getAppointConfessionWall/{periods}")
    public Information getAppointConfessionWall(@PathVariable("periods") int periods) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/getAppointConfessionWall/" + periods, Information.class);
    }

    //获取指定用户的表白墙
    @PostMapping("/getMemberConfessionWall/{memberId}")
    public Information getMemberConfessionWall(@PathVariable("memberId") long memberId) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/getMemberConfessionWall/" + memberId, null, Information.class);
    }

    //获取最大的期数
    @GetMapping("/getMaxPeriods")
    public int getMaxPeriods() {
        return restTemplate.getForObject(REST_URL_PREFIX + "/getMaxPeriods", int.class);
    }

    //表白墙点赞
    @GetMapping("/AddLoves/{confessionWallId}/{memberId}")
    public Information AddLoves(@PathVariable("confessionWallId") long confessionWallId,
                                @PathVariable("memberId") long memberId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/AddLoves/" + confessionWallId + "/" + memberId, Information.class);
    }

    //添加一条留言
    @PostMapping("/InsertConfessionWallMessage")
    public Information InsertConfessionWallMessage(@RequestBody ConfessionWallMessage ConfessionWallMessage) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/InsertConfessionWallMessage", ConfessionWallMessage, Information.class);
    }

    //按照表白墙ID获取下面的留言
    @GetMapping("/GetConfessionWallMessage/{ConfessionWallId}")
    public Information GetConfessionWallMessage(@PathVariable("ConfessionWallId") long ConfessionWallId) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/GetConfessionWallMessage/" + ConfessionWallId, Information.class);
    }

    //删除一条留言
    @PostMapping("/DeleteConfessionWallMessage")
    public Information DeleteConfessionWallMessage(@RequestBody long id) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/DeleteConfessionWallMessage", id, Information.class);
    }

    //获取指定用户的留言
    @PostMapping("/GetConfessionWallMessageByMemberId/{memberId}")
    public Information GetConfessionWallMessageByMemberId(@PathVariable("memberId") long memberId) {
        return restTemplate.postForObject(REST_URL_PREFIX + "/GetConfessionWallMessageByMemberId/" + memberId, null, Information.class);
    }

    //管理员获取尚未审批的留言
    @PostMapping("/GetNotSuggestConfessionWallMessage")
    public Information GetNotSuggestConfessionWallMessage() {
        return restTemplate.postForObject(REST_URL_PREFIX + "/GetNotSuggestConfessionWallMessage", null, Information.class);
    }

    //管理员审核表白墙留言
    @GetMapping("/AdminSuggestConfessionWallMessage/{confessionWallMessageId}/{suggestResult}")
    public Information AdminSuggestConfessionWallMessage(@PathVariable("confessionWallMessageId") long confessionWallMessageId, @PathVariable("suggestResult") int suggestResult) {
        return restTemplate.getForObject(REST_URL_PREFIX + "/AdminSuggestConfessionWallMessage/" + confessionWallMessageId + "/" + suggestResult, Information.class);
    }


}
